<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-hk">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Java," />








  <link rel="shortcut icon" type="image/x-icon" href="/blog/favicon.ico?v=5.1.0" />






<meta name="description" content="Java 编程的 151 个建议 (二)
边界测试
关于四舍五入
注意包装类型的 null 值
包装类型的比较
优先选择基本类型
优先使用整型池
不要随便设置随机种子">
<meta property="og:type" content="article">
<meta property="og:title" content="Java 编程的 151 个建议 (二)">
<meta property="og:url" content="http://jocens.oschina.io/blog/2017/03/01/151-2/index.html">
<meta property="og:site_name" content="Averson">
<meta property="og:description" content="Java 编程的 151 个建议 (二)
边界测试
关于四舍五入
注意包装类型的 null 值
包装类型的比较
优先选择基本类型
优先使用整型池
不要随便设置随机种子">
<meta property="og:updated_time" content="2017-03-20T02:32:49.836Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Java 编程的 151 个建议 (二)">
<meta name="twitter:description" content="Java 编程的 151 个建议 (二)
边界测试
关于四舍五入
注意包装类型的 null 值
包装类型的比较
优先选择基本类型
优先使用整型池
不要随便设置随机种子">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://jocens.oschina.io/blog/2017/03/01/151-2/"/>





  <title> Java 编程的 151 个建议 (二) | Averson </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-hk">

  














  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/blog/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">Averson</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
    
      <p class="site-subtitle"></p>
    
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首頁
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            歸檔
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            標籤
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="http://jocens.oschina.io/blog/blog/2017/03/01/151-2/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="Averson">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/blog/images/avatar.gif">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="Averson">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="Averson" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Java 编程的 151 个建议 (二)
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">發表於</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2017-03-01T19:00:50+08:00">
                2017-03-01
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/blog/2017/03/01/151-2/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2017/03/01/151-2/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="Java-编程的-151-个建议-二"><a href="#Java-编程的-151-个建议-二" class="headerlink" title="Java 编程的 151 个建议 (二)"></a>Java 编程的 151 个建议 (二)</h1><ul>
<li>边界测试</li>
<li>关于四舍五入</li>
<li>注意包装类型的 null 值</li>
<li>包装类型的比较</li>
<li>优先选择基本类型</li>
<li>优先使用整型池</li>
<li>不要随便设置随机种子</li>
</ul>
<a id="more"></a>
<h2 id="边界测试"><a href="#边界测试" class="headerlink" title="边界测试"></a>边界测试</h2><p>一个方法接受的参数是 <code>int</code> 类型, 三个值是必须测试的, <code>0</code>、正最大、负最小， 其中正最大和负最小是边界值， 如果三个值都没有问题， 表示方法是可靠的。</p>
<h2 id="关于四舍五入"><a href="#关于四舍五入" class="headerlink" title="关于四舍五入"></a>关于四舍五入</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">main() &#123;</div><div class="line">  <span class="comment">// 存款</span></div><div class="line">  BigDecimal d = <span class="keyword">new</span> BigDecimal(<span class="number">888888</span>);</div><div class="line">  <span class="comment">// 月利润 * 3 = 季度利润</span></div><div class="line">  BigDecimal r = <span class="keyword">new</span> BigDecimal(<span class="number">0.001875</span> * <span class="number">3</span>);</div><div class="line">  <span class="comment">// 计算利息 (RoundingMode.HALF_EVEN 表示使用银行家舍入法)</span></div><div class="line">  BigDecimal i = d.multiply(r).setScale(<span class="number">2</span>, RoundingMode.HALF_EVEN);</div><div class="line">  print(<span class="string">"季度利息是"</span> + i);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="注意包装类型的-null-值"><a href="#注意包装类型的-null-值" class="headerlink" title="注意包装类型的 null 值"></a>注意包装类型的 null 值</h2><p>基本类型和包装类型都是通过自动装箱 ( Autoboxing ) 和自动拆箱 ( AutoUnboxing ) 自由转换的. null 应该可以转换为 0 吗？显然这是错误的。因此在涉及包装类的运算过程中要做 <code>null</code> 检查。比如循环， 但是也有一些好处， 比如我们在做数据库映射的时候（ORM）的时候， 如果使用包装类型我们可以获得额外的信息（ <code>NullPointException</code> ），而如果是基础类型映射将会采取默认值。</p>
<h2 id="包装类型的比较"><a href="#包装类型的比较" class="headerlink" title="包装类型的比较"></a>包装类型的比较</h2><p>包装类是对象类型如果进行 <code>==</code> 操作不仅会比较值还会比较引用地址，所以这种比较自然会一直出现返回 <code>false</code> 的情况。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">main() &#123;</div><div class="line">  compare(<span class="keyword">new</span> Integer(<span class="number">100</span>), <span class="keyword">new</span> Integer(<span class="number">100</span>));</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">void</span> <span class="title">compare</span><span class="params">(Integet a, Integer b)</span> </span>&#123;</div><div class="line">  print(a == b); <span class="comment">// false</span></div><div class="line">  print(a &gt; b);  <span class="comment">// false</span></div><div class="line">  print(a &lt; b);  <span class="comment">// false</span></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>解决方法是使用 <code>Integer.compareTo()</code> ，使用这个方法的同时也说明了对象间的比较应该使用相应的方法而不是使用 <code>Java</code> 的默认机制。</p>
<p>下面看一下 <code>Integer.compareTo()</code> 的实现原理（一句话概述就是值比较）：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">compareTo</span><span class="params">(Integer anotherInteger)</span> </span>&#123;</div><div class="line">  <span class="keyword">return</span> compare(<span class="keyword">this</span>.value, anotherInteger.value);</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">compare</span><span class="params">(<span class="keyword">int</span> x, <span class="keyword">int</span> y)</span> </span>&#123;</div><div class="line">  <span class="keyword">return</span> (x &lt; y) ? -<span class="number">1</span> : ((x == y) ? <span class="number">0</span> : <span class="number">1</span>);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>先拆为基本类型，然后进行比较：</p>
<ul>
<li>当前值 &lt; 对比值，返回 -1</li>
<li>当前值 = 对比值，返回 0</li>
<li>当前值 &gt; 对比值，返回 1</li>
</ul>
<h2 id="优先使用整型池"><a href="#优先使用整型池" class="headerlink" title="优先使用整型池"></a>优先使用整型池</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">main() &#123;</div><div class="line">  Integer temp1 = <span class="keyword">new</span> Integer(<span class="number">100</span>);</div><div class="line">  Integer temp2 = <span class="keyword">new</span> Integer(<span class="number">100</span>);</div><div class="line">  print(temp1 == temp2); <span class="comment">// false</span></div><div class="line">  Integer temp3 = temp2;</div><div class="line">  print(temp2 == temp3); <span class="comment">// true</span></div><div class="line">  Integer temp4 = Integer.valueOf(<span class="number">100</span>);</div><div class="line">  Integer temp5 = Integer.valueOf(<span class="number">100</span>);</div><div class="line">  print(temp4 == temp5); <span class="comment">// true</span></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>第一个为 <code>false</code> 和好理解， 第二个也很好理解，为什么第三个既然会是 <code>true</code> ?</p>
<p>出现第三种结果的原因是 <code>Integer</code> 提供一个静态工厂模式的方法 <code>valueOf()</code> 并且内部缓存 <code>-128</code> 到 <code>127</code> 的常用 <code>Integer</code> 对象， 所以 <code>valueOf()</code> 在缓存范围内返回的都是缓存里的同一个对象。因此得到 <code>true</code> 的结果。</p>
<p>实现的源码如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">private</span> <span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">IntegerCache</span> </span>&#123;</div><div class="line">  <span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">int</span> low = -<span class="number">128</span>;</div><div class="line">  <span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">int</span> high;</div><div class="line">  <span class="keyword">static</span> &#123;</div><div class="line">    <span class="comment">// high value may be configured by property</span></div><div class="line">    <span class="keyword">int</span> h = <span class="number">127</span>;</div><div class="line">    <span class="comment">// ......</span></div><div class="line">  &#125;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> Integer <span class="title">valueOf</span><span class="params">(<span class="keyword">int</span> i)</span> </span>&#123;</div><div class="line">  <span class="keyword">if</span> (i &gt;= IntegerCache.low &amp;&amp; i &lt;= IntegerCache.high)</div><div class="line">  <span class="keyword">return</span> IntegerCache.cache[i + (-IntegerCache.low)];</div><div class="line">  <span class="keyword">return</span> <span class="keyword">new</span> Integer(i);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>这样在内部进行整型池的缓存有助于提高性能，节约内存空间，<strong>建议在判断对象是否相等的时候使用 <code>equals</code> 方法而不是 <code>==</code> 从而避免非预期效果</strong>。</p>
<h2 id="优先选择基本类型"><a href="#优先选择基本类型" class="headerlink" title="优先选择基本类型"></a>优先选择基本类型</h2><ul>
<li>基本类型可以变宽再变成包装类型，但是不能直接变成宽包装类型。</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// int &gt; long &gt; Long [√]</span></div><div class="line"><span class="comment">// int &gt; Long [×]</span></div><div class="line">main() &#123;</div><div class="line">  <span class="keyword">int</span> a = <span class="number">100</span>;</div><div class="line">  <span class="keyword">long</span> b = (<span class="keyword">long</span>) <span class="number">100</span>;</div><div class="line">  Long c = b;</div><div class="line">  </div><div class="line">  <span class="keyword">int</span> d = <span class="number">100</span>;</div><div class="line">  Long e = d;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">Client</span> </span>&#123;</div><div class="line">  main() &#123;</div><div class="line">    Client client = <span class="keyword">new</span> Client();</div><div class="line">    <span class="keyword">int</span> i = <span class="number">100</span>;</div><div class="line">    <span class="comment">// int &gt; long &gt; fn(long a)</span></div><div class="line">    client.fn(i);</div><div class="line">    <span class="comment">// Integer &gt; int &gt; long &gt; fn(long a)</span></div><div class="line">    client.fn(Integer.valueOf(i))</div><div class="line">  &#125;</div><div class="line">  </div><div class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">fn</span><span class="params">(<span class="keyword">long</span> a)</span> </span>&#123;</div><div class="line">    print(<span class="string">"basic type method callback"</span>);</div><div class="line">  &#125;</div><div class="line">  </div><div class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">fn</span><span class="params">(Long a)</span> </span>&#123;</div><div class="line">    print(<span class="string">"wrapper type method callback"</span>);</div><div class="line">  &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>综上所述：编码中优先使用 <code>基本数据类型</code> 。</p>
<h2 id="不要随便设置随机种子"><a href="#不要随便设置随机种子" class="headerlink" title="不要随便设置随机种子"></a>不要随便设置随机种子</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// the method print result value always same</span></div><div class="line">main() &#123;</div><div class="line">  <span class="keyword">long</span> seed = <span class="number">1000</span>;</div><div class="line">  Random r = <span class="keyword">new</span> Random(seed);</div><div class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">3</span>; i++) &#123;</div><div class="line">  	print(r.nextInt())  </div><div class="line">  &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>上述 <code>main()</code> 在同一个操作系统上，无论调用多少次都是同样的三个结果，所以如非必要不要设置随机数种子 （ random seed ) 。</p>
<p>产生随机数的方法如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">Random random = <span class="keyword">new</span> Random();</div><div class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">4</span>; i++) &#123;</div><div class="line">  System.out.println(random.nextInt());</div><div class="line">	System.out.println(Math.random());</div><div class="line">&#125;</div></pre></td></tr></table></figure>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/Java/" rel="tag"># Java</a>
          
        </div>
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2017/02/26/ArrayList/" rel="next" title="ArrayList 阅读">
                <i class="fa fa-chevron-left"></i> ArrayList 阅读
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2017/04/01/NestedScroll/" rel="prev" title="理解 NestedScrolling 机制">
                理解 NestedScrolling 机制 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>

          
          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2017/03/01/151-2/"
           data-title="Java 编程的 151 个建议 (二)" data-url="http://jocens.oschina.io/blog/blog/2017/03/01/151-2/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目錄
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            本站概覽
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/blog/images/avatar.gif"
               alt="Averson" />
          <p class="site-author-name" itemprop="name">Averson</p>
          <p class="site-description motion-element" itemprop="description"></p>
        </div>
        <nav class="site-state motion-element">
        
          
            <div class="site-state-item site-state-posts">
              <a href="/blog/archives">
                <span class="site-state-item-count">9</span>
                <span class="site-state-item-name">文章</span>
              </a>
            </div>
          

          

          
            <div class="site-state-item site-state-tags">
              <a href="/blog/tags">
                <span class="site-state-item-count">3</span>
                <span class="site-state-item-name">標籤</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Java-编程的-151-个建议-二"><span class="nav-number">1.</span> <span class="nav-text">Java 编程的 151 个建议 (二)</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#边界测试"><span class="nav-number">1.1.</span> <span class="nav-text">边界测试</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#关于四舍五入"><span class="nav-number">1.2.</span> <span class="nav-text">关于四舍五入</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#注意包装类型的-null-值"><span class="nav-number">1.3.</span> <span class="nav-text">注意包装类型的 null 值</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#包装类型的比较"><span class="nav-number">1.4.</span> <span class="nav-text">包装类型的比较</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#优先使用整型池"><span class="nav-number">1.5.</span> <span class="nav-text">优先使用整型池</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#优先选择基本类型"><span class="nav-number">1.6.</span> <span class="nav-text">优先选择基本类型</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#不要随便设置随机种子"><span class="nav-number">1.7.</span> <span class="nav-text">不要随便设置随机种子</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Averson</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 強力驅動
</div>

<div class="theme-info">
  主題 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.0"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"averson"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    
    <script src="/blog/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/blog/js/src/hook-duoshuo.js"></script>
  













  
  

  

  

  

  


</body>
</html>
